package com.platform.data.common;

import java.util.Objects;

/**
 * 常量枚举类
 *
 * @author weijun.zhu
 * @date 2025/5/11 14:43
 */
public enum CommonEnum {

    NO(0, "否"),
    YES(1, "是"),
    UNKNOWN(0, "未知"),
    NULL(0, "无"),
    ;

    /**
     * 枚举值
     */
    private final Integer code;
    /**
     * 描述
     */
    private final String desc;

    CommonEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据描述，获取枚举值
     *
     * @param desc desc
     * @return {@link CommonEnum}
     */
    public static CommonEnum getCodeByDesc(String desc) {
        for (CommonEnum anEnum : CommonEnum.values()) {
            if(Objects.equals(anEnum.desc, desc)){
                return anEnum;
            }
        }
        return null;
    }
}
